
*****************************************************************************************************************
* Replication file for "Group Appeals of Parties in Times of Economic and Identity Conflicts and Realignment"    
* published in Political Studies 
* by Simon Stuckelberger and Anke Tresch
*****************************************************************************************************************

*install grc1leg (for combined plots) 
net install grc1leg, from (http://www.stata.com/users/vwiggins)

**********
*Figure 2, Appeals to traditionally aligned economic group categories 
**********

use "data_Figure2.dta",replace 

**All traditionally aligned group categories, simple model (voter support)  
nbreg N_freq vote i.group i.Election,exposure(total_sentences) vce(cluster Party)    irr
estimates store trad1a
margins, dydx(vote) post
estimates store trad1

**Employers and employees
preserve

keep if group==1|group==3 

*Simple model (voter support) 
nbreg N_freq vote i.group i.Election,exposure(total_sentences) vce(cluster Party)    irr
estimates store trad2a
margins, dydx(vote) post
estimates store trad2

*Simple model (attitudes) 
nbreg N_freq attitudes i.group i.Election,exposure(total_sentences) vce(cluster Party)   irr
estimates store trad3a
margins, dydx(attitudes) post
estimates store trad3

*Full model (voter support + attitudes) 
nbreg N_freq vote attitudes i.group i.Election,exposure(total_sentences) vce(cluster Party)   irr
estimates store trad4a
margins, dydx(vote attitudes) post
estimates store trad4

restore

** Plot
*Style 
grstyle init 
grstyle color background white 
grstyle set legend 6, nobox 
graph set window fontface "Times New Roman"

label variable vote "Voter support" 
label variable attitudes "Pos. attitudes" 

*Left-side plot (all group categories) 
graph drop _all
coefplot (trad1,mlcolor(gray) mfcolor(gray) ciopts(lcolor(gray)) label(Simple Model)),  legend(order(2 "Simple model" 4 "Full model") on) ///
 xline(0,lcolor(black)) subtitle(, fcolor(white) lcolor(white))  msize(0.5) name(trad_left) xlabel(0(2)14) title(All trad. aligned group categories, size(large) color(black))
 
*Right-side plot (Employers and employees) 
coefplot (trad2,offset(0.1) mlcolor(gray) mfcolor(gray) ciopts(lcolor(gray)) label(Simple Model))(trad3,offset(0.1) mlcolor(gray) mfcolor(gray) ciopts(lcolor(gray)))(trad4,offset(-0.1)mlcolor(black) mfcolor(black) ciopts(lcolor(black)) label(Full Model)),  legend(order(2 "Simple model" 6 "Full model") on) ///
 xline(0,lcolor(black)) subtitle(, fcolor(white) lcolor(white))  msize(0.5) name(trad_right) xlabel(0(2)14) title(Large emp. & employees, size(large) color(black))

*combine plots 
grc1leg2 trad_left trad_right, legendfrom(trad_right) name(trad_combined,replace)
gr draw trad_combined,  ysize(1) xsize(2.5)
graph export "Figure2.pdf", replace

*Regression Table 
esttab trad1a trad2a trad3a trad4a using "Figure2_table.rtf", ///
replace title(Traditionally aligned economic group categories) se label star(* 0.05 ** 0.01 *** 0.001) sfmt(3) compress nogaps obslast order(vote attitudes) transform(exp(@) exp(@)) b(%5.3f)


**********
*Figure 3, Appeals to realigned economic group categories
**********

use "data_Figure3.dta",replace 

**All realigned group categories
nbreg N_freq vote i.group i.Election,exposure(total_sentences) vce(cluster Party)  irr
estimates store real1a
margins, dydx(vote ) post
estimates store real1

**Workers and poor people 
preserve
keep if group==1|group==4

*Simple model (voter support) 
nbreg N_freq vote i.group i.Election,exposure(total_sentences) vce(cluster Party)    irr
estimates store real2a
margins, dydx(vote) post
estimates store real2

*Simple model (attitudes) 
nbreg N_freq attitudes i.group i.Election,exposure(total_sentences) vce(cluster Party)  irr
estimates store real3a
margins, dydx(attitudes) post
estimates store real3

*Full model (voter support + attitudes) 
nbreg N_freq vote attitudes i.group i.Election,exposure(total_sentences) vce(cluster Party)   irr
estimates store real4a
margins, dydx(vote attitudes) post
estimates store real4

restore

**Plot 
label variable vote "Voter support" 
label variable attitudes "Pos. attitudes" 

graph drop _all
*Left-side plot (all group categories) 
coefplot (real1,mlcolor(gray) mfcolor(gray) ciopts(lcolor(gray)) label(Simple Model)),  legend(order(2 "Simple model" 4 "Full model") on) ///
 xline(0,lcolor(black)) subtitle(, fcolor(white) lcolor(white))  msize(0.5) name(real_left) xlabel(-2(2)10) title(All realigned group categories, size(large)color(black))

*Right-side plot (workers and poor people) 
coefplot (real2,offset(0.1) mlcolor(gray) mfcolor(gray) ciopts(lcolor(gray)) label(Simple Model))(real3,offset(0.1) mlcolor(gray) mfcolor(gray) ciopts(lcolor(gray)))(real4,offset(-0.1)mlcolor(black) mfcolor(black) ciopts(lcolor(black)) label(Full Model)),  legend(order(2 "Simple model" 6 "Full model") on) ///
 xline(0,lcolor(black)) subtitle(, fcolor(white) lcolor(white))  msize(0.5) name(real_right) xlabel(-2(2)10) title(Workers & poor people, size(large)color(black))

*Combine plots 
grc1leg2 real_left real_right, legendfrom(real_right) name(real_combined,replace)
gr draw real_combined,  ysize(1) xsize(2.5)
graph export "Figure3.pdf", replace

*Regression table
esttab real1a real2a real3a real4a  using "Figure3_table.rtf", ///
replace title(Realigned economic group categories) se label star(* 0.05 ** 0.01 *** 0.001) sfmt(3) compress nogaps obslast order(vote attitudes) transform(exp(@) exp(@)) b(%5.3f)



**********
*Figure 4, Appeals to IP group categories
**********

use "data_Figure4.dta", replace

*Simple model (voter support) 
nbreg N_freq vote i.group i.Election,exposure(total_sentences)  vce(cluster Party) irr
estimates store ip1a
margins, dydx(vote) post
estimates store ip1

*Simple model (attitudes)
nbreg N_freq attitudes i.group i.Election,exposure(total_sentences) vce(cluster Party)  irr
estimates store ip2a
margins, dydx(attitudes) post
estimates store ip2

*Full model (voter support + attitudes)
nbreg N_freq vote attitudes i.group i.Election,exposure(total_sentences) vce(cluster Party)   irr
estimates store ip3a
margins, dydx(vote attitudes) post
estimates store ip3


**Plot 
label variable vote "Voter support" 
label variable attitudes "Pos. attitudes" 

graph drop _all
coefplot (ip1,offset(0.1) mlcolor(gray) mfcolor(gray) ciopts(lcolor(gray)) label(Simple Model))(ip2,offset(0.1) mlcolor(gray) mfcolor(gray) ciopts(lcolor(gray)))(ip3,offset(-0.1) mlcolor(black) mfcolor(black) ciopts(lcolor(black)) label(Full Model)),  legend(order(2 "Simple model" 6 "Full model") on) ///
 xline(0,lcolor(black)) subtitle(, fcolor(white) lcolor(white))  msize(0.5) name(ip) xlabel(-2(2)10) title(All IP group categories, size(large) color(black))
graph export "Figure4.pdf", replace

*Regression table
esttab ip1a ip2a ip3a using "Figure4_table.rtf", ///
replace title(IP group categories) se label star(* 0.05 ** 0.01 *** 0.001) sfmt(3) compress nogaps obslast order(vote attitudes) transform(exp(@) exp(@)) b(%5.3f)


**********
*Figure 5, Reference logic 
**********

*** Positive group appeals  

use "data_Figure5_pos.dta",replace 

nbreg N_freq vote i.group i.Election,exposure(total_sentences) vce(cluster Party)   irr
estimates store pos1a
margins, dydx(vote ) post
estimates store pos1

nbreg N_freq attitudes i.group i.Election,exposure(total_sentences) vce(cluster Party) irr
estimates store pos2a
margins, dydx(attitudes) post
estimates store pos2

nbreg N_freq vote attitudes i.group i.Election,exposure(total_sentences) vce(cluster Party)  irr
estimates store pos3a
margins, dydx(vote attitudes) post
estimates store pos3

*Regression table
esttab pos1a pos2a pos3a using "Figure5_pos_table.rtf", ///
replace title(Positive group appeals (Reference logic)) se label star(* 0.05 ** 0.01 *** 0.001) sfmt(3) compress nogaps obslast order(vote attitudes) transform(exp(@) exp(@)) b(%5.3f)

 
***Negative group appeals 

use "data_Figure5_neg.dta",replace 

nbreg N_freq vote i.group i.Election,exposure(total_sentences) vce(cluster Party)   irr
estimates store neg1a
margins, dydx(vote) post
estimates store neg1

nbreg N_freq attitudes i.group i.Election,exposure(total_sentences) vce(cluster Party) irr
estimates store neg2a
margins, dydx(attitudes) post
estimates store neg2

nbreg N_freq vote attitudes i.group i.Election,exposure(total_sentences) vce(cluster Party)  irr
estimates store neg3a
margins, dydx(vote attitudes) post
estimates store neg3

*Regression table
esttab neg1a neg2a neg3a using "Figure5_neg_table.rtf", ///
replace title(Negative group appeals (Reference logic)) se label star(* 0.05 ** 0.01 *** 0.001) sfmt(3) compress nogaps obslast order(vote attitudes) transform(exp(@) exp(@)) b(%5.3f)


**Plot 
label variable vote "Voter Support" 
label variable attitudes "Pos. Attitudes" 

graph drop _all
*Positive group appeals
coefplot (pos1,offset(0.1) mlcolor(gray) mfcolor(gray) ciopts(lcolor(gray)) label(Simple Model))(pos2,offset(0.1) mlcolor(gray) mfcolor(gray) ciopts(lcolor(gray))label(Simple Model))(pos3,offset(-0.1) mlcolor(black) mfcolor(black) ciopts(lcolor(black)) label(Full Model)), legend(order(2 "Simple model" 6 "Full model") on) ///
xline(0,lcolor(black)) subtitle(, fcolor(white) lcolor(white))  msize(0.5) name(pos) xlabel(-2(2)14) title(Positive group appeals (with att. data), size(large) color(black))

*Negative group appeals
coefplot (neg1,offset(0.1) mlcolor(gray) mfcolor(gray) ciopts(lcolor(gray)) label(Simple Model))(neg2, offset(0.1) mlcolor(gray) mfcolor(gray) ciopts(lcolor(gray)))(neg3,offset(-0.1)mlcolor(black) mfcolor(black) ciopts(lcolor(black)) label(Full Model)), legend(order(2 "Simple model" 6 "Full model") on) ///
 xline(0,lcolor(black)) subtitle(, fcolor(white) lcolor(white))  msize(0.5) name(neg) xlabel(-14(2)2) title(Negative group appeals, size(large) color(black))

*Combine positive and negative group appeals 
grc1leg2 pos neg, legendfrom(neg) name(ref_combined,replace)
gr draw ref_combined,  ysize(1) xsize(2.5)
graph export "Figure5.pdf", replace




